const TokenKey = 'token'
const UserDataKey = 'userData'
import store from '@/store'

export function getToken() {
  return sessionStorage.getItem(TokenKey)
}

export function setToken(token) {
  return sessionStorage.setItem(TokenKey, token)
}

export function removeToken() {
  return sessionStorage.removeItem(TokenKey)
}

export function getUserData() {
  return JSON.parse(sessionStorage.getItem(UserDataKey))
}

export function setUserData(data) {
  return sessionStorage.setItem(UserDataKey, JSON.stringify(data))
}

export function removeUserData() {
  return sessionStorage.removeItem(UserDataKey)
}

export function removeVuexUserInfo() {
  store.commit('user/REMOVE_USERINFO')
}

// 清除登录信息
export function clearUserCache() {
  removeToken()
  removeUserData()
  removeVuexUserInfo()
}
